package com.bms.hystrix.service.zl;

import com.bms.hystrix.interfaces.zl.ZiLiaoHystrix;
import com.bms.hystrix.pojo.ZiLiao;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class ZiLiaoService {

    @Resource
    private ZiLiaoHystrix ziLiaoHystrix;
    //全部查询
    @HystrixCommand(fallbackMethod = "checkError")
    public Map chaXunAll(ZiLiao ziLiao) {
        return ziLiaoHystrix.chaXunAll(ziLiao);
    }
    //查询分页
    @HystrixCommand(fallbackMethod = "checkError")
    public Map chaXunFenYe(int page, String biaoTi,String shangChuanShiJian) {
        return ziLiaoHystrix.chaXunFenYe(page,biaoTi,shangChuanShiJian);
    }
    //基于id查询
    @HystrixCommand(fallbackMethod = "checkError")
    public Map chaXunById(Integer id) {
        return ziLiaoHystrix.chaXunById(id);
    }
    //基于id删除
    @HystrixCommand(fallbackMethod = "checkError")
    public Map shanChuById(String id) {
        return ziLiaoHystrix.shanChuById(id);
    }
    //基于id更新数据
    @HystrixCommand(fallbackMethod = "checkError")
    public Map gengXinById(ZiLiao ziLiao) {
        return ziLiaoHystrix.gengXinById(ziLiao);
    }
    //新增
    @HystrixCommand(fallbackMethod = "checkError")
    public Map xinZeng(ZiLiao ziLiao) {
        return ziLiaoHystrix.xinZeng(ziLiao);
    }
    //浏览数量
    @HystrixCommand(fallbackMethod = "checkError")
    public Map liuLanShuLiang(ZiLiao ziLiao) {
        return ziLiaoHystrix.liuLanShuLiang(ziLiao);
    }
    //下载量
    @HystrixCommand(fallbackMethod = "checkError")
    public Map xiaZaiLiang(ZiLiao ziLiao) {
        return ziLiaoHystrix.xiaZaiLiang(ziLiao);
    }



    public Map checkError(String biaoTi) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        map.put("biaoTi", biaoTi);
        return map;
    }
}
